﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ArrayListTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = { "嘻嘻", "哈哈", "哦哦", "嗯嗯" };
            ArrayList al = new ArrayList();
            int i = al.IndexOf("abc");
            Console.WriteLine(i);







            ArrayList list1 = new ArrayList() { "aaa", "bbb", "abc", 123, 456 };
            ArrayList newList = new ArrayList();
            for (int j = 0; j < list1.Count; j = j + 2)
            {
                newList.Add(list1[i]);
            }
            foreach (var v in newList)
            {
                Console.WriteLine(v);
            }









            ArrayList list2 = new ArrayList() { "aaa", "bbb", "abc", 123, 456 };
            ArrayList insertList = new ArrayList() { "A", "B", "C" };
            list2.InsertRange(1, insertList);
            foreach (var v in list2)
            {
                Console.WriteLine(v);
            }

            ArrayList arrayList = Product.GetArrayList();
            List<Product> list3 = Product.GetList();
           
            
            //1、使用继承IComparer接口的函数来进行排序
            arrayList.Sort(new ProductCompare());
            foreach (Product product in arrayList)
            {
                Console.WriteLine(product.ToString());
            }


            Console.WriteLine("---------------------------");
            //2、使用继承IComparer<T>接口的函数来进行排序 
            list3.Sort(new ProductCompareT());
            foreach (Product product1 in list3)
            {
                Console.WriteLine(product1.ToString());
            }
            Console.WriteLine("---------------------------");
           
            
            //3、使用委托来进行排序
            list3.Sort(delegate(Product x, Product y)
            {
                return x.Price.CompareTo(y.Price); });
                foreach (Product product2 in list3)
            {
                Console.WriteLine(product2.ToString());
            }
           
                
             //4、使用Lambda表达式来进行排序；
            list3.Sort((x, y) => x.Price.CompareTo(y.Price));
            foreach (Product product3 in list3) {
                Console.WriteLine(product3.ToString());

            }
            
            
            //5、使用扩展方法来进行排序
            foreach (Product product4 in list3.OrderBy(p=>p.Price))
            {
                Console.WriteLine(product4.ToString());

            }
            




                Person[] persons = {
                new Person("Lili", "Female"),
                new Person("Heicer", "Male"),
                new Person("Lucy", "Female")
            };
                Array.Sort(persons);
            foreach (Person p in persons)
            {
                Console.WriteLine(p);
            }
        }

    }
          

    
}
